﻿using System;using GKQC.Language;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using GQKC.Language;

namespace GKQC.Language
{
    public class QMessageBox
    {
        static string tishi = LanguageHelper.GetLanguageText("提示");
        static string errorString = LanguageHelper.GetLanguageText("异常");

        public const int GW_CHILD = 5;
        public const int GW_HWNDNEXT = 2;

        public static DialogResult Show(string msg)
        {
            return MessageBox.Show(LanguageHelper.GetLanguageText(msg));
        }

        public static void Show1(string msg)
        {
            QMsgBox.ShowInfo(LanguageHelper.GetLanguageText(msg), string.Empty, tishi, false, string.Empty);
        }

        public static DialogResult Show(string msg, string title)
        {
            return MessageBox.Show(LanguageHelper.GetLanguageText(msg), LanguageHelper.GetLanguageText(title));
        }

        public static DialogResult ShowError(string msg, string title)
        {
            return MessageBox.Show(LanguageHelper.GetLanguageText(msg), LanguageHelper.GetLanguageText(title)
                , MessageBoxButtons.OK,MessageBoxIcon.Error);
        }

        public static DialogResult ShowError(string msg)
        {
            return MessageBox.Show(LanguageHelper.GetLanguageText(msg), LanguageHelper.GetLanguageText(tishi)
                , MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        public static void ShowError1(string msg)
        {
            QMsgBox.ShowError(msg);
        }

        /// <summary>
        /// essageBoxButtons.OKCancel
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public static DialogResult ShowQuestion(string msg, string title)
        {
            return MessageBox.Show(LanguageHelper.GetLanguageText(msg), LanguageHelper.GetLanguageText(title)
                , MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

        }


        /// <summary>
        /// essageBoxButtons.OKCancel
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public static DialogResult ShowQuestion1(string msg)
        {
            return QMsgBox.ShowQuestion(LanguageHelper.GetLanguageText(msg));
        }
        

        /// <summary>
        /// MessageBoxButtons.OKCancel
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static DialogResult ShowQuestion(string msg)
        {
            return MessageBox.Show(LanguageHelper.GetLanguageText(msg), tishi
                , MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
        }

        public static DialogResult ShowWarning(string msg, string title)
        {
            return MessageBox.Show(LanguageHelper.GetLanguageText(msg), LanguageHelper.GetLanguageText(title)
                , MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        public static DialogResult ShowWarning(string msg)
        {
            return MessageBox.Show(LanguageHelper.GetLanguageText(msg), tishi
                , MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        public static void ShowWarning1(string msg)
        {
            QMsgBox.ShowWarning(LanguageHelper.GetLanguageText(msg));
        }

        public static DialogResult ShowInformation(string msg, string title)
        {
            return MessageBox.Show(LanguageHelper.GetLanguageText(msg), LanguageHelper.GetLanguageText(title)
                , MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public static DialogResult ShowInformation(string msg)
        {
            return MessageBox.Show(LanguageHelper.GetLanguageText(msg), tishi
                , MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public static DialogResult Show(string msg, string title, MessageBoxButtons button, MessageBoxIcon icon)
        {
            return MessageBox.Show(LanguageHelper.GetLanguageText(
                        msg), LanguageHelper.GetLanguageText(title), button, icon);
        }

        public static DialogResult Show(string msg, string title, MessageBoxButtons button, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
        {
            return MessageBox.Show(LanguageHelper.GetLanguageText(
                        msg), LanguageHelper.GetLanguageText(title), button, icon, defaultButton);
        }

        readonly static string nonet = "Connection open error";

        public static DialogResult ShowException(Exception exception)
        {
            StringBuilder strInfo = new StringBuilder();

            if (exception.Message.Contains(nonet))
                strInfo.Append("断网了，请稍后再试....");
            else
            try
            {
                strInfo.Append("\r\n---" + DateTime.Now.ToString() + "---\r\n");
                strInfo.Append("错误列表:\r\n");

                int exCount = 1;
                Exception currException = exception;
                do
                {
                    strInfo.Append(exCount + ") ");
                    strInfo.Append(currException.GetType().Name);
                    strInfo.Append("\r\n信息: ");
                    strInfo.Append(currException.Message);
                    strInfo.Append("\r\n");
                    exCount++;
                    currException = currException.InnerException;
                }
                while (currException != null);
                strInfo.Append("\r\n" + exception.StackTrace);
            }
            catch { }

            return MessageBox.Show(LanguageHelper.GetLanguageText(strInfo.ToString()), LanguageHelper.GetLanguageText(errorString)
                , MessageBoxButtons.OK, MessageBoxIcon.Error);

            strInfo.Length = 0;
        }

        public static void ShowException1(Exception exception)
        {
            StringBuilder strInfo = new StringBuilder();

            if (exception.Message.Contains(nonet))
                strInfo.Append("断网了，请稍后再试....");
            else
                try
            {
                strInfo.Append("\r\n---" + DateTime.Now.ToString() + "---\r\n");
                strInfo.Append("错误列表:\r\n");

                int exCount = 1;
                Exception currException = exception;
                do
                {
                    strInfo.Append(exCount + ") ");
                    strInfo.Append(currException.GetType().Name);
                    strInfo.Append("\r\n信息: ");
                    strInfo.Append(currException.Message);
                    strInfo.Append("\r\n");
                    exCount++;
                    currException = currException.InnerException;
                }
                while (currException != null);
                strInfo.Append("\r\n" + exception.StackTrace);
            }
            catch { }

            QMsgBox.ShowError(exception.Message, strInfo.ToString(), errorString
                , false, string.Empty);

            strInfo.Length = 0;
        }

        
    }
}
